import {message} from 'antd';
import {formatMessage} from './intl';

export const newOrUpdateOrderValidator = (data, planItemDetails, actualItemDetails) => {
    const requiredFields = [];
    if(!data || !data.brandId)
        requiredFields.push(
            formatMessage({
                id: 'validator.brandId',
                defaultMessage: '品牌'
            })
        );
    if(!data || !data.marketingActivityItemCategoryId)
        requiredFields.push(
            formatMessage({
                id: 'validator.marketingActivityItemCategoryId',
                defaultMessage: '营销活动编号'
            })
        );
    if(!data || !data.mainItem)
        requiredFields.push(
            formatMessage({
                id: 'validator.mainItem',
                defaultMessage: '计划主项目'
            })
        );
    if(!data || !data.actualMainItem)
        requiredFields.push(
            formatMessage({
                id: 'validator.actualMainItem',
                defaultMessage: '实际主项目'
            })
        );
    if(!data || !data.scope)
        requiredFields.push(
            formatMessage({
                id: 'validator.scope',
                defaultMessage: '营销目标'
            })
        );
    if(!data || !data.customerQTY)
        requiredFields.push(
            formatMessage({
                id: 'validator.customerQTY',
                defaultMessage: '目标用户量'
            })
        );
    if(!data || !data.amount)
        requiredFields.push(
            formatMessage({
                id: 'validator.planAmount',
                defaultMessage: '计划费用'
            })
        );
    if(!data || !data.actualCustomerQTY)
        requiredFields.push(
            formatMessage({
                id: 'validator.actualCustomerQTY',
                defaultMessage: '实际用户量'
            })
        );
    if(!data || !data.totalFee)
        requiredFields.push(
            formatMessage({
                id: 'validator.totalFee',
                defaultMessage: '实际费用'
            })
        );
    if(!data || !data.actualSituation)
        requiredFields.push(
            formatMessage({
                id: 'validator.actualSituation',
                defaultMessage: '完成情况'
            })
        );
    if(!data || !data.opinion)
        requiredFields.push(
            formatMessage({
                id: 'validator.opinion',
                defaultMessage: '改善意见'
            })
        );
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.requied',
            defaultMessage: '必填'
        })}`);
        return false;
    }
    if(!planItemDetails || (planItemDetails && planItemDetails.length === 0)) {
        message.warning(formatMessage({
            id: 'validator.message.detailQuantity',
            defaultMessage: '计划项目清单不能为空！'
        }));
        return false;
    }
    if(planItemDetails.find(d => d.marketingActivityItemCategoryId === undefined || d.marketingActivityItemCategoryId === 0)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.marketingActivityItemCategory',
            defaultMessage: '计划项目清单中项目类型必填!'
        })}`);
        return false;
    }
    if(planItemDetails.find(d => d.item === undefined || d.item === 0)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.item',
            defaultMessage: '计划项目清单中项目必填!'
        })}`);
        return false;
    }
    if(planItemDetails.find(d => d.amount === undefined || d.amount === 0)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.amount',
            defaultMessage: '计划项目清单中费用必填!'
        })}`);
        return false;
    }
    if(!actualItemDetails || (actualItemDetails && actualItemDetails.length === 0)) {
        message.warning(formatMessage({
            id: 'validator.message.detailQuantitys',
            defaultMessage: '实际项目不能为空！'
        }));
        return false;
    }
    if(actualItemDetails.find(d => d.marketingActivityItemCategoryId === undefined || d.marketingActivityItemCategoryId === 0)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.marketingActivityItemCategoryIds',
            defaultMessage: '实际项目清单中项目类型必填!'
        })}`);
        return false;
    }
    if(actualItemDetails.find(d => d.item === undefined || d.item === 0)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.items',
            defaultMessage: '实际项目清单中项目必填!'
        })}`);
        return false;
    }
    if(actualItemDetails.find(d => d.amount === undefined || d.amount === 0)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.amounts',
            defaultMessage: '实际项目清单中费用必填!'
        })}`);
        return false;
    }
    return true;
};
